
package com.healthcare;

import java.io.IOException;
import java.io.PrintWriter;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import webservices.HealthCareServerProxy;



import com.google.gson.Gson;




import beans.Articles;

/**
 * Servlet implementation class UserRegistration
 */
public class SearchArticles extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public SearchArticles() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String query = request.getParameter("query");
		System.out.print("state" +query);
	
		    		        int page = 1;
		        int recordsPerPage = 3;
		        if(request.getParameter("page") != null)
		            page = Integer.parseInt(request.getParameter("page"));
		        DAO dao = new DAO();
		        System.out.println("hello");
		        List<Articles> list = dao.viewArticles((page-1)*recordsPerPage,
		                                 recordsPerPage, query);
		        int noOfRecords = dao.getNoOfRecords();
		        int noOfPages = (int) Math.ceil(noOfRecords * 1.0 / recordsPerPage);
		        request.setAttribute("articleList", list);
		        request.setAttribute("isEmptyList", "true");
		        request.setAttribute("noOfPages", noOfPages);
		        request.setAttribute("currentPage", page);
		        RequestDispatcher view = request.getRequestDispatcher("/SearchArticles.jsp");
		        view.forward(request, response);
		 }
	

	

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

	}
}